package ihm;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class FenetreConnection extends JFrame implements ActionListener {

	private JPanel contentPane;
	private JPasswordField txtMdp;
	private JTextField txtLogin;
	private JButton btnQuitter;	
	private JButton btnValider;
	
	String login;
	char[] mdp;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FenetreConnection frame = new FenetreConnection();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FenetreConnection() {
	
		
	
		setTitle("Connection");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 474, 298);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblLogin = new JLabel("Login :");
		lblLogin.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblLogin.setBounds(134, 38, 43, 32);
		contentPane.add(lblLogin);
		
		JLabel lblMotDePasse = new JLabel("Mot de passe :");
		lblMotDePasse.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblMotDePasse.setBounds(92, 91, 85, 14);
		contentPane.add(lblMotDePasse);
		
		txtMdp = new JPasswordField();
		txtMdp.addActionListener(this);
		txtMdp.setBounds(198, 89, 86, 20);
		contentPane.add(txtMdp);
		
		txtLogin = new JTextField();
		txtLogin.addActionListener(this);
		txtLogin.setBounds(198, 45, 86, 20);
		contentPane.add(txtLogin);
		txtLogin.setColumns(10);
		
		btnValider = new JButton("Valider");
		btnValider.addActionListener(this);
		btnValider.setBounds(86, 166, 91, 23);
		contentPane.add(btnValider);
		
		btnQuitter = new JButton("Quitter");
		btnQuitter.addActionListener(this);
		btnQuitter.setBounds(288, 166, 91, 23);
		contentPane.add(btnQuitter);
		
		JLabel lblErreur = new JLabel("Le login et/ou le mot de passe n'est pas valide ");
		lblErreur.setForeground(Color.RED);
		lblErreur.setBounds(122, 136, 230, 14);
		contentPane.add(lblErreur);
		lblErreur.setVisible(false);
		
		JLabel lblFond = new JLabel("");
		lblFond.setIcon(new ImageIcon(FenetreConnection.class.getResource("/image/fond2.png")));
		lblFond.setBounds(0, 0, 458, 260);
		contentPane.add(lblFond);
	}

	public void actionPerformed(ActionEvent evt) {
		if(evt.getSource()==btnQuitter)
		{
			System.exit(0);
		}
		if(evt.getSource()==btnValider)
		{
			
			if (this.txtLogin.getText().isEmpty() || this.txtMdp.getPassword().equals(""))
			{
				JOptionPane.showMessageDialog(null, "Veuillez bien saisir un login et un mot de passe");
			}	
		
			login = this.txtLogin.getText();
			mdp = this.txtMdp.getPassword();
			
			
		
		
		
		}
	}
}
